<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>19.sort排序算法原理实现</title>
</head>

<body>
  <script>
    let arr = [1, 5, 7, 3, 4];
    function sort (array, callback) {
      for (const n in array) {
        for (const m in array) {
          if (callback(array[n], array[m]) < 0) {
            const temp = array[n];
            array[n] = array[m];
            array[m] = temp;
          }
        }
      }
      return array;
    }
    arr = sort(arr, function (a, b) {
      return a - b;
    });
    console.log(arr);
  </script>
</body>

</html>